#ifndef MDEVICEMANAGER_H
#define MDEVICEMANAGER_H

#include <QObject>

#include "usb.h"
#include "requests.h"
#include "usbconfig.h"
#include "libusb_func.h"
#include "opendevice.h"

#include "CONST.h"

namespace Mikroakustika {
namespace MDeviceChecker {

class MDeviceManager : public QObject {
    Q_OBJECT

public:

    void initManager(QObject *parent);
    explicit MDeviceManager(QObject *parent = 0);
    
private:
    QString DecToHex(int Value);

    devBusInf devBusInfTmp;
    connDevicesType connectedDevices;
    avSerPort availableSerialPorts;

    usb_dev_handle      *usbDevHandle;
    struct usb_bus      *bus;
    struct usb_device   *dev;

    char ManufacturerString[maxSymbolsChipDescription];
    char ProductString[maxSymbolsChipDescription];
    char iSerialNumber[maxSymbolsChipDescription];

    bool isNeedManufacturerConnected;

    QString captionOfSerialPort;

private slots:
    void deviceAdd();
    void deviceRem();
    void scanDevOnBuses(devStatus);

    void scanDevices(connDevicesType &conDev);
    void scanAvailableSerialPorts(avSerPort &serPorts);
    QString compareDevLists(connDevicesType &currentList,
                         connDevicesType &newList,
                         devStatus devStatusAction);

    QString getPortNameForFTDI(const QString &vid,
                               const QString &pid,
                               const QString ftdiSerial);

    void strikeOffVirtualPorts(connDevicesType &usbDevList,
                               avSerPort &serPorts);

    void debugPrintDevices(const connDevicesType &conDev) const;
    void debugPrintSerialPorts(const avSerPort &serPorts) const;

signals:
    void refreshDeviceList(connDevicesType&,
                           avSerPort&,
                           QString&,
                           devStatus,
                           bool);
    void sendBaloon(QString &txt);

};

}
}
#endif // MDEVICEMANAGER_H
